package com.ltkj.shop.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.ltkj.common.core.domain.R;
import com.ltkj.shop.domain.request.ShopGoodsParams;
import com.ltkj.shop.domain.vo.ShopGoodsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ltkj.common.log.annotation.Log;
import com.ltkj.common.log.enums.BusinessType;
import com.ltkj.common.security.annotation.RequiresPermissions;
import com.ltkj.shop.domain.ShopGoods;
import com.ltkj.shop.service.IShopGoodsService;
import com.ltkj.common.core.web.controller.BaseController;
import com.ltkj.common.core.web.domain.AjaxResult;
import com.ltkj.common.core.utils.poi.ExcelUtil;
import com.ltkj.common.core.web.page.TableDataInfo;

/**
 * 文创商品Controller
 * 
 * @author xupf
 * @date 2023-08-29
 */
@Api(tags = "文创商品")
@RestController
@RequestMapping("/goods")
public class ShopGoodsController extends BaseController
{
    @Autowired
    private IShopGoodsService shopGoodsService;

    /**
     * 查询文创商品列表
     */
    @ApiOperation("查询文创商品列表")
    @RequiresPermissions("shop:goods:list")
    @GetMapping("/list")
    public TableDataInfo list(ShopGoods shopGoods)
    {
        startPage();
        List<ShopGoodsVo> list = shopGoodsService.selectShopGoodsList(shopGoods);
        return getDataTable(list);
    }

    /**
     * 导出文创商品列表
     */
//    @ApiOperation("导出文创商品列表")
//    @RequiresPermissions("shop:goods:export")
//    @Log(title = "文创商品", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, ShopGoods shopGoods)
//    {
//        List<ShopGoods> list = shopGoodsService.selectShopGoodsList(shopGoods);
//        ExcelUtil<ShopGoods> util = new ExcelUtil<ShopGoods>(ShopGoods.class);
//        util.exportExcel(response, list, "文创商品数据");
//    }

    /**
     * 获取文创商品详细信息
     */
    @ApiOperation("获取文创商品详细信息")
    @RequiresPermissions("shop:goods:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shopGoodsService.selectShopGoodsById(id));
    }

    /**
     * 新增文创商品
     */
    @ApiOperation("新增文创商品")
    @RequiresPermissions("shop:goods:add")
    @Log(title = "文创商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopGoods shopGoods)
    {
        return success(shopGoodsService.insertShopGoods(shopGoods));
    }

    /**
     * 修改文创商品
     */
    @ApiOperation("修改文创商品")
    @RequiresPermissions("shop:goods:edit")
    @Log(title = "文创商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ShopGoods shopGoods)
    {
        return toAjax(shopGoodsService.updateShopGoods(shopGoods));
    }

    /**
     * 上架/下架商品
     */
    @ApiOperation("上架/下架商品")
    @RequiresPermissions("shop:goods:edit")
    @Log(title = "文创商品", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/onOff")
    public AjaxResult onOff(@Valid @RequestBody ShopGoodsParams shopGoods)
    {
        return success(shopGoodsService.onOffShopGoods(shopGoods));
    }

    /**
     * 删除文创商品
     */
    @ApiOperation("删除文创商品")
    @RequiresPermissions("shop:goods:remove")
    @Log(title = "文创商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shopGoodsService.deleteShopGoodsByIds(ids));
    }
}
